/**
 * Created by Administrator on 2017/6/26.
 */

const schedule = require('node-schedule');
const variable = require('../config/variable.js');
const mem = require('../util/mem.js');
const push = require('./push.js');

//module.exports = interval;

function interval() {
    // 建立一个时间循环的默认规则
    var rule = new schedule.RecurrenceRule();
    // 增加一个每秒执行的内容
    //var times = [];
    //for (var i = 1; i < 60; i++) {
    //    times.push(i);
    //}
    //rule.second = times;
    // 开始动作
    schedule.scheduleJob(rule, function () {
        var lossTime = Date.now() - (variable.config.linkLossTime * 1000);
        for (var i in mem.clients) {
            if (!mem.clients[i].user) {
                continue;
            }
            if (lossTime > mem.clients[i].updateTime) {
                push.sendError(10004, i);
                mem.clients[i].close();
            }
        }
    });
}

interval();